using System;
using System.Collections.Generic;
using Microsoft.Pex.Framework;

namespace Benchmarks
{
    public class Command
    {
        private IMethodInfo methodInfo;
        private string name;
        private List<IMethodInfo> lists = new List<IMethodInfo>();

        public string Name
        {
            get { return name; }
        }

        public Command()
        {
        }

        public Command(IMethodInfo _methodInfo, string name)
        {
            this.methodInfo = _methodInfo;
            this.name = name;
        }

        public void Execute(object[] parameters)
        {
            if (parameters.Length != methodInfo.ParameterInfos.Length)
            {
                throw new Exception("not match");
            }
            methodInfo.Execute(parameters);
        }

        public void AddMethodInfo(IMethodInfo info)
        {
            lists.Add(info);
        }

        public void ExecuteMultiple(object[] parameters)
        {
            foreach (IMethodInfo info in lists)
            {
                if (parameters.Length != info.ParameterInfos.Length)
                {
                    throw new Exception("not match");
                }
                info.Execute(parameters);
            }
        }
    }

    public interface IMethodInfo
    {
        object[] ParameterInfos { get; }
        void Execute(object[] parameters);
    }

//    public class MethodInfo:IMethodInfo
//    {
//        public object[] infos;
//
//        public MethodInfo(object[] infos)
//        {
//            this.infos = infos;
//        }
//
//        public object[] ParameterInfos
//        {
//            get { return infos; }
//        }
//
//        public void Execute(object[] parameters)
//        {
//            foreach (object o in parameters)
//            {
//                Console.WriteLine("object is: " + o);
//            }
//        }
//    }

    [PexClass(typeof (Command))]
    public partial class CommandTest
    {
        [PexMethod]
        public void TestExecute(Command command, object[] parameters)
        {
            command.Execute(parameters);
        }

        [PexMethod]
        [PexMe.Attribute.FieldAccessObserver]
        [PexMe.Attribute.InsufficientObjectFactoryObserver]
        public void TestExecuteMultiple(Command command, object[] parameters)
        {
            command.ExecuteMultiple(parameters);
        }
    }
}